<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ include file="/taglibs.jsp"%>
<html>
<head>
<title>IT管理后台</title>
<link rel="stylesheet" type="text/css" href="/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/js/themes/icon.css">
<script type="text/javascript" src="/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/js/easyui_validatebox.js"></script>
<script type="text/javascript" src="/js/locale/easyui-lang-zh_CN.js"></script>
<style type="text/css">
td {
	font-size: 13px
}
table.ttb{border-left:solid 1px #99bbe8;border-top: solid 1px #99bbe8;}
table.ttb td{word-break: break-all; word-wrap:break-word;vertical-align: top; padding-left:8px; border-right: solid 1px #99bbe8;border-bottom: solid 1px #99bbe8; line-height: 24px; font-size: 12px;}
.bg001{font-weight: bold; color: #333; background-color: #edf4fc}
</style>
	<script>
	    var tag = null;
		$(function(){
			 $('#tab').tree({
				  url:'/itmanager/yh/qxjson',
				  animate:true,
				  dnd: true,
				  checkbox:true,
				  onClick:function(node){
						$(this).tree('toggle', node.target);
				  },
				  onLoadSuccess:function(node,data){
					  $('#tab').tree('expandAll');
				  }
			 });
			 
			 $('#tab1').datagrid({
				  title:'角色信息',
				  url:'/itmanager/yh/jswhjson',
				  queryParams:{sfyx:1},
				  idField:'id',
				  rownumbers:true,
				  singleSelect:true,
				  iconCls:'icon-friends',
				  fit:true,
				  border:false,
				  pagination:true,
				  pageList:[2,10,20,30,40,50],
				  remoteSort: false,
				  columns:[
				    [
				     {title:'角色名称',field:'mc',width:300}
				    ]
				  ],
				  toolbar:[
				     {id:'6',text:'保存',disabled:true,iconCls:'icon-save',handler:function(){
				    	 var t = [];
				    	 var checked = $('#tab').tree('getChecked'); 
				    	 var js = $('#tab1').datagrid('getSelected');
				    	 if( checked.length>0 && js != null){
						     for(var i=0;i<checked.length;i++){
						    	 var p = checked[i].id;
						    	 var tmp = p.toString().split(",");
						    	 t = t.concat(tmp);
						     }
						     t = clearRepeat(t);
						     t = t.join(",");
						     $.ajax({
						    	 url:'/itmanager/yh/jsqxcz',
						    	 data:{jsid:js.id,qxid:t},
						    	 method:'post',
						    	 success:function(data){
						    		 if(data == 'success'){
						    		 	$.messager.alert('友情提示','<br/>保存成功！','right');
						    		 }
						    	 }
						     });
				    	 }else{
				    		 $.messager.alert('友情提示','<br/>请先选择角色和菜单！','error');
				    	 }
				     }}
				  ],
				  onClickRow:function(rowIndex,rowData){
					  $('#tab').tree('options').url = '/itmanager/yh/qxjson?jsid='+rowData.id;
					  $('#tab').tree('reload');
				  }
			 });
			 
			 var ens='${param.en}';
			 var en=ens.split(":");
			 for(var i=0;i<en.length;i++){
				 if(en[i] != "" && en[i] != null){
				 	$("#"+en[i]).linkbutton('enable');
				 }
			 }
			 
		});
		
		var clearRepeat = function(a) {
			var c = new Array(), b = {};
			for ( var i = 0; i < a.length; i++) {
				if (!b[a[i]]) {
					b[a[i]] = 1;
					c.push(a[i]);
				}
			}
			return c;
		}
	</script>
</head>
<body class="easyui-layout">
	<div id="center" region="center" border="false" split="true">
		<table id="tab1"></table>
	</div>
	<div id="east" region="east" style="width: 500" border="false" split="true" title='权限列表' iconCls="icon-save">
		<ul id="tab"></ul>
	</div>
</body>
</html>